import { Context } from "egg";

export default function uiMiddleware() {
  return async (ctx: Context, next: () => Promise<any>) => {
    const url = ctx.request.url;
    if (url.indexOf("stream") >= 0 || url === "/" || url === "/login") {
      if (url.indexOf(".") >= 0) {
        await ctx.app.forward(ctx, (url: string) => url.replace("stream", "public"));
      } else {
        await ctx.forward("public/index.html");
      }
    } else {
      await next();
    }
  };
}
